/* 
 * File:   Candidate.cpp
 * Author: user
 * 
 * Created on July 26, 2014, 11:51 AM
 */

#include "Candidate.h"

Candidate::Candidate() :User("",2) {
}

Candidate::Candidate(const Candidate& orig) {
}

Candidate::~Candidate() {
}

void Candidate::printMenu()
{
    cout << endl;
    cout << "*****Candidate menu*****" << endl;
    cout << "---------------------------------" << endl << endl ;
    cout << "1)     Select exam topic and start test" << endl;
    cout << "2)     View test summary" << endl;
    cout << "0)     Log out" << endl << endl;
    //cout << "99)     Quit program" << endl << endl;
}

bool Candidate::menuAction(int iSelection,bool& isExitProgram, int& loginStatus)
{
    switch (iSelection)
    {
        case 0: //Log out
        {
            menuItemAction(LOG_OUT,isExitProgram,loginStatus);
            break;
        }
        case 1: //Select a exam topic and start a test
        {
            if (_myTest.extractExamTopic(_loginAccount.getCreateBy()))
            {
                if (_myTest.promptUserForSelectingExamTopic())
                {
                    system("clear");
                    cout << "[-----Test: " << _myTest.getExamTopic() << "-----]"<< endl;
                    //record the tart DateTiem
                    time_t rawTime;
                    struct tm* timeInfo;

                    time(&rawTime);
                    timeInfo = localtime(&rawTime);
                    
                    if (_myTest.extractQuestion())
                    {
                        _myTest.updateTestToDB(_userID, _myTest.getExamTopic(),timeInfo);
                    }
                    cout << endl;
                }
            }
            break;
        }
        case 2: //View test summary
        {
            system("clear");
            cout << "[-----Test Summary-----]"<< endl;
            _myTest.extractTestSummary(_userID);
            break;
        }
        case 99:
        {
            menuItemAction(QUIT_PROGRAM,isExitProgram,loginStatus); 
            break;
        }
    }
    
    return true;
}

